package jsj.mynet;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class MySendThread implements Runnable {
	DatagramSocket ds;//套工具
	
	public MySendThread(DatagramSocket ds) {
		super();
		this.ds = ds;
	}

	@Override
	public void run() {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));//接纳键盘输入，放入数据缓冲区
		String line;
		try {
			while((line = br.readLine()) != null){//将数据缓冲区中的数据调入字符串
				if(line.equals("886")){
					break;
				}
				byte[] bys = line.getBytes();//转换成数据流
				DatagramPacket dp = new DatagramPacket(bys, bys.length, InetAddress.getLocalHost(), 10086);//参数分别是数据流，数据流长度，地址，端口
				ds.send(dp);//发送
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		ds.close();//记得关闭资源

	}

}
/*
首先，继承runnable接口，然后准备套工具。

*/
